/**
 * Copyright (c)  HeiFeiDeFengZheng.Co.Ltd. All rights reserved.
 **/
package com.hongfu.adruid.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import com.alibaba.druid.util.JdbcUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.sql.DataSource;

/**
 * 功能描述：
 *
 * @author huifeidefengzheng
 * @since 2023-09-07
 *
 **/
@Slf4j
//@Configuration
public class DataSourceConfig extends DruidDataSourceAutoConfigure {

    @Override
    public DataSource dataSource() {
        DruidDataSource dataSource = (DruidDataSource) super.dataSource();
        String url = dataSource.getUrl();
        String dbType = JdbcUtils.getDbType(url, null);
        if (StringUtils.isEmpty(dbType)) {
            log.info("db type");
            dataSource.setDbType("customDbType");
        }
        return dataSource;
    }
}
